<%-- Created by IntelliJ IDEA. --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
  <head>
    <title>停车场车位租赁管理系统</title>
  </head>
  <body>
      <h1>停车场车位租赁管理系统</h1>
      <form action="SelectServlet" method="post">
        <tr>
          <td>车牌号：<input type="text" name="carNum">
            <button type="submit">搜索</button>
          </td>
        </tr>
      </form>
      <table>
        <tr>
          <td><a href="add.jsp"><button>车位租赁</button></a></td>
        </tr>
        <tr>
          <th>租赁人姓名</th>
          <th>车牌号</th>
          <th>租赁状态</th>
          <th>到期日期</th>
          <th>操作</th>
        </tr>
        <c:forEach items="${list}" var="r">
          <tr>
            <td>${r.userName}</td>
            <td>${r.carNum}</td>
            <td>${r.status==0 ? '租赁中' : '已到期'}</td>
            <td>${r.maturityDate}</td>
            <td>
              <a href="UpdateServlet?id=${r.id}&status=${r.status}">${r.status==0 ? '退租' : '已到期'}</a>
              <a href="#" onclick="del(${r.id})">删除</a>
            </td>
          </tr>
        </c:forEach>
      </table>
      <a href="ListServlet?pageNo=1">首页</a>
        <a href="ListServlet?pageNo=${pageNo-1}">上一页</a>
        <a href="ListServlet?pageNo=${pageNo+1}">下一页</a>
  <script src="js/jquery-1.8.3.js"></script>
  <script>
     function del(id) {
       if (confirm("确定要删除吗?")){
         $.post("DeleteServlet","id="+id,function (date) {
            if (date>0){
              alert("删除成功！");
              location.href = 'ListServlet';
            }
         })
       }
     }
  </script>
  </body>
</html>